package com.huabo.system.controller;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.UUID;

public class FxglUtil {

    private static String webRootPath = "";

    public FxglUtil() {
    }

    public static String getselect(Object s, int type) {
        if (s.equals("闭") && type == 1) {
            return "selected='selected'";
        } else {
            return s.equals("开") && type == 0 ? "selected='selected'" : "";
        }
    }

    public static String strCheck(String s) {
        return s != null ? s : "";
    }

    public static String strPar(Integer s) {
        return s == 1 ? "弃用" : "使用";
    }

    public static Object strCheck(Object s) {
        return s != null ? s : "";
    }

    public static String checkDC(Object s) {
        if (s.equals("D")) {
            return "借";
        } else {
            return s.equals("C") ? "贷" : "";
        }
    }

    public static String getTimeString() {
        DecimalFormat timeFormat4 = new DecimalFormat("0000;0000");
        Calendar cal = Calendar.getInstance();
        String val = String.valueOf(cal.get(1));
        val = val + timeFormat4.format((long)cal.get(6));
        val = val + UUID.randomUUID().toString().replaceAll("-", "");
        return val;
    }

    public static String getStrFromObject(Object s) {
        return s == null ? "" : s.toString();
    }

    public static String getPwdFromName(String name) {
        if (name == null) {
            name = "abc123321";
        }

        if (name.equals("25982FA6")) {
            return "1";
        } else if (name.equals("68C21TG8")) {
            return "1";
        } else if (name.equals("HBAUDIT2")) {
            return "1";
        } else {
            String result = (new StringBuilder(name)).reverse().toString();
            result = result.toLowerCase();
            return result;
        }
    }

    public static String getWebRootPath() {
        return webRootPath;
    }

    public static void setWebRootPath(String webRootPath) {
        FxglUtil.webRootPath = webRootPath;
    }
}
